package com.genius.smsdao.dormitorymanage.domain;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.genius.smsbase.Domain.BaseEntity;
import com.genius.smsdao.studentmanage.domain.Student;
import com.genius.smsdao.teachermanage.domain.Department;

import javax.persistence.*;
import java.util.List;

/**
 * @Entity:Dormitory 宿舍实体类
 * 对应数据库表名：dormitory
 * @author：
 */
@Entity
@Table(name = "dormitory")
public class Dormitory extends BaseEntity<Long> {

    @Column
    private String name;

    //宿舍到公寓多对一关系
    @JsonIgnoreProperties(value = "dormitoryList")
    @ManyToOne(targetEntity = Apartment.class,fetch = FetchType.EAGER)
    @JoinColumn(name = "apartment_id",referencedColumnName = "id")
    private Apartment apartment;

    //宿舍到学生一对多关系
    @JsonIgnoreProperties(value = "dormitory",allowSetters = true)
    @OneToMany(mappedBy = "dormitory",cascade = {CascadeType.REMOVE,CascadeType.REFRESH},fetch = FetchType.EAGER)
    private List<Student> studentList;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Apartment getApartment() {
        return apartment;
    }

    public void setApartment(Apartment apartment) {
        this.apartment = apartment;
    }

    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }

    @Override
    public String toString() {
        return "Dormitory{" +
                "name='" + name + '\'' +
                ", apartment=" + apartment +
                ", createTime=" + createTime +
                ", updateTime=" + updateTime +
                ", id=" + id +
                '}';
    }
}

